#include "app/libc/std.h"
#include "app/libc/print.h"
#include "app/libc/type.h"
#include "app/libdraw/draw.h"

//__asm__ ("1:\n\t"
//         "mov $0x3f8, %dx\n\t"
//         "mov $'C', %ax\n\t"
//         "out %ax, %dx\n\t"
//         "mov $1000, %rdi\n\t"
//         "mov $0, %rax\n\t"
//         "syscall\n\t"
//         "jmp 1b");
//

/*
* Using app/libc/start.S (starting from virtual address 0x100000) invoke `call main` and jumps to this point
* Simulate packaging application app, including C library startup file to call the application main() function
*/
int main() {
  // draw
  struct mode_info mode_info;
  get_mode_info(&mode_info);
  // print(0x8801);
  // print(mode_info.fbbase);
  // print(mode_info.hres);
  // print(mode_info.vres);
  // print(mode_info.bpp);
  // print(0x8802);
  uint64_t fbbase = fbmap();
  // print(fbbase); // Incorrect fbbase, not start with 0xe000000 !
  // print(0x8803);
  uint64_t cnt = 0;
  uint32_t colors[] = { RED, GREEN, BLUE };

  void* shm = shm_open("shm-1");
  *((char*)shm) = 'S'; // write to shm

  while(1) {
    print('A');

    draw_rect(100, 100, 150, 100, colors[cnt++ % 3], fbbase, &mode_info);

    sleep(1000);
  }
}